package util;

/**
* This class implements in a static way some useful mathematical methods.
* 
* @author ter-topcased-ups
* @version 0.01, 2008/18/03
* @see 
*/

public class MathPerso {

	/**
	 * @param a
	 * @param b (>= 0)
	 * @return a^b
	 */
	static public  int pow(int a, int b) {
		if (b <0) {
			throw	new IllegalArgumentException ("second argument must be a natural integer") ;
		}
		
		//Exponentiating by squaring algorithm
		if (b ==0) {
			return 1 ;
		} else 	if (b == 1) {
			return a ; 									// if b==1
		} else if (b % 2 == 0) {
			return pow(a*a,b/2) ; 				// if b is even
		} else {
			return a*pow(a*a,(b-1)/2) ;	 // if b is odd (and so >2)
		}		
	}
	
	
}
